package com.zz.utils;

import java.sql.*;

/**
 * Author: zhangzhen
 * DATE: Created in 2018/8/16 16:23
 * Description:
 */
public class DB {

        public static Connection createConn() {
            Connection conn = null;
            try {
                Class.forName("com.mysql.jdbc.Driver");
                conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/drdc", "root", "root");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return conn;
        }
        public static PreparedStatement prepare(Connection conn, String sql) {
            PreparedStatement ps = null;
            try {
                ps = conn.prepareStatement(sql);

            } catch (SQLException e) {
                e.printStackTrace();
            }
            return ps;
        }
        public static void close(Connection conn) {
            try {
                conn.close();
                conn = null;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        public static void close(Statement stmt) {
            try {
                stmt.close();
                stmt = null;
            } catch (SQLException e) {
                e.printStackTrace();
            }

        }
        public static void close(ResultSet rs) {
            try {
                rs.close();
                rs = null;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
}
